# url：http://www.bjhospital.net/
# 用例1：
# 搜索骨科—>点击搜索—>点击出来的第一个链接—>断言文本内容
from selenium import webdriver #导入依赖
option = webdriver.EdgeOptions() # todo：chrome浏览器配置项
option.add_experimental_option("detach", True)# todo：浏览器不会自动关闭
# driver = webdriver.Edge(options=option)
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
class SearchName:
    def __init__(self,driver):
        self.driver= driver
        self.driver.implicitly_wait(10)
        self.driver.get("http://www.bjhospital.net/")
        self.driver.maximize_window()
    def input_shuru(self,text:str):
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CLASS_NAME,'keyword'))).send_keys(text)
# driver.find_element(By.CLASS_NAME,'keyword').send_keys("骨科")
    def input_shousuo(self):
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CLASS_NAME,'btn'))).click()
# driver.find_element(By.CLASS_NAME,'btn').click()
    def input_one(self):
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,"/html/body/div[4]/ul/li[1]/div[1]/h5/a"))).click()
# driver.find_element(By.XPATH,"/html/body/div[4]/ul/li[1]/div[1]/h5/a").click()
    def input_duanyan(self):
        win = driver.window_handles
        self.driver.switch_to.window(win[-1])
        text_result =self.driver.find_element(By.XPATH,"/html/body/div[3]/div/div/article/h1").text
        print(text_result)
        assert text_result =="毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开"
    def quit(self):
        print(driver.title)
        self.driver.quit()

if __name__ == '__main__':
    driver = webdriver.Edge(options=option)
    a = SearchName(driver)
    a.input_shuru("骨科")
    a.input_shousuo()
    a.input_one()
    a.input_duanyan()
    a.quit()


